#include <bits/stdc++.h>
#define int long long 
using namespace std;
int arr[105];

void solve(){
	int n;
	cin >> n;
	for (int i=1;i<=n;i++) {
		cin >> arr[i];
	}
	set<int, greater<int>>s;
	int sum = 0;
	for (int i=1;i<=n;i++) {
		for (int j=i+1;j<=n;j++) {
			for (int k=j+1;k<=n;k++) {
				sum = arr[i] + arr[j] + arr[k];
				s.insert(sum);
			}
		}
	}
	auto it = s.begin();
	for (int i=1;i<=2;i++) {
		it++;
	}
	cout << (*it);
}


signed main(){
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int t=1;
	while (t--) {
		solve();
	}
	return 0;
}
